package cn.dotiedu.test;

import org.apache.commons.io.IOUtils;

import java.io.*;
import java.net.Socket;

public class HttpClient {
    public static void main(String[] args) throws IOException {

        Socket socket = new Socket("localhost",8080);
        OutputStream outputStream = socket.getOutputStream();
        InputStream inputStream = socket.getInputStream();

        outputStream.write("GET / HTTP/1.1\r\n".getBytes());
        outputStream.write("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\r\n".getBytes());
        outputStream.write("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\r\n".getBytes());
        outputStream.write("\r\n".getBytes());

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String line;
        while((line=bufferedReader.readLine())!=null){
            System.out.println(line);

        }


    }
}
